home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1994 / 8 / 05 / term-4.0-source.lha / termEmulationProcess.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-19  |  1.7 KB  |  119 lines

  1. /*
  2. **    termEmulationProcess.c
  3. **
  4. **    Terminal emulation process
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11. #include "termEmulationProcess.h"
  12.  
  13. STATIC struct Process *EmulationProcess;
  14.  
  15. STATIC VOID __saveds
  16. EmulationProcessEntry(VOID)
  17. {
  18.     if(TerminalQueue = CreateMsgQueue(NULL,40))
  19.     {
  20.         ULONG         Mask = SIG_KILL | TerminalQueue -> SigMask;
  21.         struct DataMsg    *Msg;
  22.         BOOLEAN         Done = FALSE;
  23.  
  24.         EmulationProcess = (struct Process *)FindTask(NULL);
  25.  
  26.         Signal(ThisProcess,SIG_HANDSHAKE);
  27.  
  28.         do
  29.         {
  30.             if(Wait(Mask) & SIG_KILL)
  31.                 break;
  32.  
  33.             ObtainSemaphore(&TerminalSemaphore);
  34.  
  35.             ClearCursor();
  36.  
  37.             while(Msg = GetMsgItem(TerminalQueue))
  38.             {
  39.                     /* Remember the data. */
  40.  
  41.                 if(RememberOutput)
  42.                     RememberOutputText(Msg -> Data,Msg -> Size);
  43.  
  44.                 (*ConProcessData)(Msg -> Data,Msg -> Size);
  45.  
  46.                 DeleteMsgItem(Msg);
  47.  
  48.                 if(SetSignal(0,0) & SIG_KILL)
  49.                 {
  50.                     Done = TRUE;
  51.  
  52.                     break;
  53.                 }
  54.             }
  55.  
  56.             DrawCursor();
  57.  
  58.             ReleaseSemaphore(&TerminalSemaphore);
  59.         }
  60.         while(!Done);
  61.  
  62.         DeleteMsgQueue(TerminalQueue);
  63.  
  64.         TerminalQueue = NULL;
  65.     }
  66.  
  67.     Forbid();
  68.  
  69.     EmulationProcess = NULL;
  70.  
  71.     Signal(ThisProcess,SIG_HANDSHAKE);
  72. }
  73.  
  74. VOID
  75. DeleteEmulationProcess()
  76. {
  77.     if(EmulationProcess)
  78.     {
  79.         Forbid();
  80.  
  81.         Signal(EmulationProcess,SIG_KILL);
  82.  
  83.         ClrSignal(SIG_HANDSHAKE);
  84.  
  85.         Wait(SIG_HANDSHAKE);
  86.  
  87.         Permit();
  88.     }
  89. }
  90.  
  91. BOOLEAN
  92. CreateEmulationProcess()
  93. {
  94.     if(!EmulationProcess)
  95.     {
  96.         Forbid();
  97.  
  98.         if(CreateNewProcTags(
  99.             NP_Name,    "term Emulation Process",
  100.             NP_Priority,    SysBase -> ThisTask -> tc_Node . ln_Pri,
  101.             NP_Entry,    EmulationProcessEntry,
  102.             NP_StackSize,    6000,
  103.             NP_WindowPtr,    Window,
  104.         TAG_DONE))
  105.         {
  106.             ClrSignal(SIG_HANDSHAKE);
  107.  
  108.             Wait(SIG_HANDSHAKE);
  109.         }
  110.  
  111.         Permit();
  112.     }
  113.  
  114.     if(EmulationProcess)
  115.         return(TRUE);
  116.     else
  117.         return(FALSE);
  118. }
  119.